package com.heima.mapper;

import com.heima.pojo.Partner;
import com.heima.pojo.dto.PartnerQueryParamDto;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface PartnerMapper {

    void addPartner(Partner partner);

    @Select("select name from tb_partner where name = #{name}")
    String selectPartnerByName(String name);

    @Select("select mobile from tb_partner where mobile = #{mobile}")
    String selectPartnerByMobile(String mobile);


    List<Partner> selectPartnerList(PartnerQueryParamDto partnerDto);
    @Select("select p.*,count(*) vm_count from tb_partner p left join tb_vending_machine vm on p.id = vm.owner_id where p.id = #{id} group by p.id;")
    Partner selectPartnerById(int id);
    @Update("update tb_partner p set p.name = #{name},p.contact = #{contact},p.mobile = #{mobile},p.ratio = #{ratio} where p.id = #{id} ;")
    void updatePartner(Partner partner);
    @Delete("delete from tb_partner where id = #{id}")
    int deletePartner(int id);
}
